package com.outsider.util;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class DD {
	public static JSONObject getProductInfo(String url){
		JSONObject result=new JSONObject();
		OkHttp3 okHttp3=OkHttp3.getInstance();
		String html=okHttp3.get(url);
		Pattern p=Pattern.compile("<p id=\"dd-price\">.*?</span>(.*?)</p>",Pattern.DOTALL);
		Matcher matcher=p.matcher(html);
		matcher.find();

		
        Double price=Double.parseDouble(matcher.group(1).replaceAll("-&yen(.*?)$", ""));
		String code=url.split("/|\\.")[5];
		
        result.put("code", code);
		result.put("price", price);
		return result;
	}
	public static String getProductPic(String url){
		OkHttp3 okHttp3=OkHttp3.getInstance();
		Map<String,String> header=new HashMap<>();
		String html=okHttp3.get(url);
		Pattern p=Pattern.compile("src=\"(.*?jpg)\"");
		Matcher matcher=p.matcher(html);
		matcher.find();
		return matcher.group(1);
	}

	public static void main(String[] args){
		System.out.println(DD.getProductPic("http://product.dangdang.com/24032082.html"));
	}
}
